package com.jec.module.sysconfig.service.convertor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jec.module.sysconfig.dao.MeetingRepository;
import com.jec.module.sysconfig.entity.MeetingConfig;
import com.jec.module.sysmonitor.dao.NetUnitRepository;
import com.jec.utils.Response;

/**
 * Created by jeremyliu on 9/26/16.
 */
@Service
public class MeetingConvertor implements Convertor<MeetingConfig>{

    @Autowired
    private NetUnitRepository netUnitRepository;

    @Autowired
    private MeetingRepository meetingRepository;

    @Override
    public Response process(MeetingConfig meeting) {
        Response response = Response.Builder().status(Response.STATUS_PARAM_ERROR);

        if(netUnitRepository.findOne(meeting.getNetunit()) == null)
            return response.message("网元不存在");
        
        if(meetingRepository.existsByNetunitAndCodeAndIdNot(
        		meeting.getNetunit(),
        		meeting.getCode(),
        		meeting.getId()))
            return response.message("该网元业务为"+meeting.getCode()+"已配置");

        return response.status(Response.STATUS_SUCCESS);
    }

    @Override
    public Response checkBeforeRemove(int id) {
        return null;
    }
}
